﻿using Adnc.Application.Shared;
using Adnc.Application.Shared.Dtos;
using Adnc.WebApi.Shared;
using Microsoft.AspNetCore.Mvc;
using WYT.Sys.Application.Contracts.Dtos.Edu;
using WYT.Sys.Application.Contracts.Services;

namespace WYT.Sys.WebApi.Controllers
{
    /// <summary>
    /// 教育服务
    /// </summary>
    [Route("sys/[Controller]")]
    [ApiController]
    public class EduController  : AdncControllerBase
    {
        private readonly IEduAppService _eduAppService;

        private readonly IUserContext _userContext;

        public EduController(IEduAppService eduAppService
            , IUserContext userContext)
        { 
            _eduAppService = eduAppService;
            _userContext = userContext;
        }

        /// <summary>
        /// 获取课时
        /// </summary>
        /// <param name="course">课程ID</param>
        /// <param name="phase">阶段ID 0:所有课程</param>
        /// <returns></returns>
        [HttpGet("lesson")]
        public async Task<WYTActionResult<List<EduLessonDto>>> GetEduLessonByGroupId([FromQuery] long course, [FromQuery] long phase)
        {
            return Success(await _eduAppService.GetEduLessonByGroupId(course,phase));
        }
        /// <summary>
        /// 获取课程阶段
        /// </summary>
        /// <param name="course"></param>
        /// <returns></returns>
        [HttpGet("phase")]
        public async Task<WYTActionResult<List<EduPhaseDto>>> GetEduPhase([FromQuery] long course)
        {
            return Success(await _eduAppService.GetEduPhase(course));
        }

        /// <summary>
        /// 获取课程列表
        /// </summary>
        /// <param name="type">类型 0：商学院；1：健康之道</param>
        /// <returns></returns>
        [HttpGet("group")]
        public async Task<WYTActionResult<List<EduGroupListDto>>> GetGroupList([FromQuery]int type)
        {
            return Success(await _eduAppService.GetGroupList(type));
        }

        /// <summary>
        /// 获取课程详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("course")]
        public async Task<WYTActionResult<EduGroupDetailDto>> GetCourseDetail([FromQuery] SimpleDto<long> input)
        {
            return Success(await _eduAppService.GetCourseDetail(input.Value));
        }

        /// <summary>
        /// 阅读记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("record")]
        public async Task<WYTActionResult> ReadingRecords(EduReadingRecordsDto input)
        {
            return Success(await _eduAppService.ReadingRecords(_userContext.Id, input));   
        }
    }
}
